package com.lcz.mobilesafe.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lcz.mobilesafe.R;
import com.lcz.mobilesafe.activity.BaseApplication;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hp on 2017/3/2.
 */

public class HomeAdapter extends BaseAdapter {
    private Context context;
    //标题
    String[] title = {"手机防盗", "通讯卫士", "软件管理", "进程管理", "流量统计", "手机杀毒",
            "缓存清理", "高级工具", "设置中心"};
    //图标
    int[] pics = {R.drawable.home_safe, R.drawable.home_callmsgsafe, R.drawable.home_apps,
            R.drawable.home_taskmanager, R.drawable.home_netmanager, R.drawable.home_trojan,
            R.drawable.home_sysoptimize, R.drawable.home_tools, R.drawable.home_settings};


    @Override
    public int getCount() {
        return title.length;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(BaseApplication.getApplication(), R.layout.home_item, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.ivPics.setImageResource(pics[i]);
        holder.tvTitle.setText(title[i]);
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.iv_pics)
        ImageView ivPics;
        @BindView(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
